package cn.my.springHDFS.util;


import cn.my.springHDFS.web.ManagementController;
import org.apache.hadoop.conf.Configuration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Leo on 2017/6/22.
 */
@Component
public class ToolUtil {

    //获取配置文件对象
    PropertyUtil property = new PropertyUtil();

    //logger类
    private static final Logger logger = LoggerFactory.getLogger(ToolUtil.class);

    //默认端口号(暂时不使用配置文件进行修改)
    private static final String port = "9000";

    //获取master的IP
    private String master = property.getProperty("master");

    //获取standby的ip
    private String master_standby = property.getProperty("master_standby");

    //切换IP
    public List<Object> ipSwitch(String isActive){
        Configuration configuration = new Configuration();
        List<Object> returnList = new ArrayList<>();

        if (Boolean.valueOf(isActive)){
            configuration.set("fs.default.name", master + ":" + port);
            returnList.add(0, configuration);
            returnList.add(1, master);
        }
        else {
            configuration.set("fs.default.name", master_standby + ":" + port);
            returnList.add(0, configuration);
            returnList.add(1, master_standby);
        }
        return returnList;
    }

    public String getMaster() {
        return master;
    }

    public void setMaster(String master) {
        this.master = master;
    }

    public String getMaster_Standby() {
        return master_standby;
    }

    public void setMaster_Standby(String master_standby) {
        this.master_standby = master_standby;
    }
}
